#pragma once
#include<vector>
#include<windows.h>
#include<d3d9.h>
#include<d3dx9.h>
#include "DataDef.h"
#include "ErrorHandler.h"

typedef std::vector<float> Float1D;
typedef std::vector<Float1D> Float2D;
typedef std::vector<Float2D> Float3D;

class Water
{
public:

	Water(const LPDIRECT3DDEVICE9 p_dx_Device, const WORD width = WATER_DEPTH, const WORD depth = WATER_WIDTH);

	~Water(void);

	// Draw the mesh.
	void Draw();

	// Update the water physics.
	void UpdateWater();

	void UpdateWaterMesh();

	// Create a splash in the water.
	void DimpleWater(const FLOAT x, const FLOAT z, const FLOAT force = 1.0f, const FLOAT range = 1.0f);

	void positionWater(const FLOAT x, const FLOAT y, const FLOAT z) const;

	const LPD3DXMESH getMesh()  const
	{
		return waterMesh;
	}

	const WORD GetWidth() const
	{
		return width;
	}

	const WORD GetDepth() const
	{
		return depth;
	}

private:
	static const UINT WATER_DEPTH = 40;

	static const UINT WATER_WIDTH = 40;

	// Create the internal mesh.
	bool GenerateWaterMesh (const LPDIRECT3DDEVICE9 p_dx_Device, const WORD width, const WORD depth);

	Float3D waterBank;
	
	// Dampening is how fast the waves degrade.
	FLOAT dampening;
	
	WORD dimpleCnt;

	LPD3DXMESH waterMesh;

	ID3DXBuffer *adjacencyBuffer;

	WORD width, depth;

	UINT waterUpdateRate;

	//if the surface is perfectly flat then this value remains 0
	FLOAT dyna;
};
